package com.sunday.volunteer.window;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sunday.volunteer.R;
import com.sunday.volunteer.entity.Product;
import com.sunday.volunteer.weights.roundimageview.RoundedImageView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2015/11/20.
 */
public class ProductWindow extends MyWindow {

    private View contentView;
    @Bind(R.id.imageView)
    RoundedImageView imageView;
    @Bind(R.id.price)
    TextView price;
    @Bind(R.id.is_store)
    TextView is_store;
    @Bind(R.id.product_count)
    TextView product_count;
    @Bind(R.id.add_product)
    TextView add_product;
    @Bind(R.id.reduce)
    ImageView reduce;
    @Bind(R.id.add)
    ImageView add;

    private int num = 1;
    public ProductWindow(Context context, Product product, View.OnClickListener onClickListener) {
        super(context);

        LayoutInflater mLayoutInflater = LayoutInflater.from(context);
        contentView = mLayoutInflater.inflate(R.layout.window_product, null);
        ButterKnife.bind(this, contentView);
        setContentView(contentView);
        add_product.setOnClickListener(onClickListener);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setCornerRadius(12);
        price.setText(String.format("%s" , product.getPrice()));
        Picasso.with(context).load(product.getImage()).centerCrop().resize(150,150).placeholder(R.drawable.default_error).into(imageView);
        product_count.setText(String.valueOf(num));
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num++;
                product_count.setText(String.valueOf(num));
            }
        });

        reduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(num <= 1){
                    return;
                }
                num--;
                product_count.setText(String.valueOf(num));
            }
        });

    }

    public int getNum() {
        return num;
    }
}
